package de.slothsoft.network;

import java.io.IOException;
import java.io.OutputStream;

import javax.swing.JEditorPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;

public class JEditorPaneStream extends OutputStream {

	private final AttributeSet attributes = new SimpleAttributeSet();
	private final JEditorPane output;

	public JEditorPaneStream(JEditorPane output) {
		this.output = output;
	}

	@Override
	public void write(int c) throws IOException {
		try {
			int length = this.output.getDocument().getLength();
			this.output.getDocument().insertString(length, Character.toString((char) c), this.attributes);
		} catch (BadLocationException e) {
			throw new IOException(e);
		}
	}
}
